<template>
	<main-content>
		<view class="content-color">
			<view class="" v-if="formType=='view'">
				<view class="p-t-16">
				</view>
				<view class="view-group m-t-8" v-for="(group,groupI) in viewConfig" :key="groupI">
					<view class="view-item p-x-16 p-y-12 flex flex-row justify-between items-center"
						style="border-bottom: 1rpx solid #e1e1e1;" v-for='(item,i) in group' :key="i">
						<view class="list-title">
							{{item.label}}
						</view>
						<view class="" style="max-width: 70%;">
							<view class=""
								v-if="item.dataIndex =='invoiceUrl' && !$System.isEmpty(formData[item.dataIndex])">
								<u-image width="100%" height="300rpx" :src="formData[item.dataIndex]"></u-image>
							</view>
							<view class="" v-else>
								{{
								item?.customRender ? item.customRender({formData,text:formData[item.dataIndex]}) : formData[item.dataIndex]
							}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</main-content>
</template>
<script setup name='index'>
	import {
		reactive,
		ref,
		getCurrentInstance,
		computed,
		nextTick
	} from 'vue'
	import {
		onLoad,
		onShow,
		onReady
	} from '@dcloudio/uni-app'
	import {
		useCommonStore
	} from '@/stores/common.js'
	import {
		useUserStore
	} from '@/stores/user.js'
	import {
		ZZB_AGENT_NO_STATUS,
		AUTH_BUSS_TYPE,
		ZZB_NO_TYPE_MCH
	} from '@/common/dict.js'
	import {
		debounce,
		selectDictLabel,
		parseTime,
		formatToMoney
	} from '@/common/common.js'
	import {
		profitApi
	} from '@/pages-menus/common/api/profit/index.js'
	import myArea from '@/components/my-area/index.vue'
	import {
		isMulPassword,
		validatePhoneNot
	} from '@/common/validate'
	const commonStore = useCommonStore()
	const {
		proxy
	} = getCurrentInstance()

	const formType = ref('view')

	// 确认密码校验
	const validateConfirmPassword = (rule, value, callback) => {
		if (value !== formData.value.pwd) {
			callback(new Error('两次输入的密码不一致'))
		} else {
			callback()
		}
	}

	const maiColor = computed(() => {
		return proxy.$System.maiColor.value
	})
	const initForm = {
		id: undefined,
		no: undefined, //商户账号
		noType: undefined, //商户账号
		pwd: undefined, //商户密码
		confirmPwd: undefined, //商户密码
		companyName: undefined, //公司名称
		companyAbbrName: undefined, //公司简称
		name: undefined, //联系人
		phone: undefined, //联系方式
		areaCode: undefined, //城市，所属区/县ID
		addr: undefined, //地址
		authBussType: undefined, //授权业务，0全部，1开设代理商，2开商户
		status: undefined, //状态，0正常使用，1禁止开代理商，2禁止开商户，3禁止操作人员登录，4系统停止使用，5停止全部收款，6全部禁用
		exhibitionId: undefined, //开户业务人员
		// profitDrawType: undefined, //分润提现，0统一提现，1逐级提现
	}
	const formData = ref({
		...initForm
	})

	const viewConfig = ref([
		[{
			label: '提现日期',
			dataIndex: 'drawTime',
			customRender: (data) => {
				return parseTime(data.text)
			},
		}, {
			label: '提现金额',
			dataIndex: 'drawAmt',
			customRender: (data) => {
				return `${formatToMoney(data.text / 100)}元`
			},
		}, {
			label: '提现后余额',
			dataIndex: 'eAmt',
			customRender: (data) => {
				return `${formatToMoney(data.text / 100)}元`
			},
		}, {
			label: '手续费 (1%)',
			dataIndex: 'fee',
			customRender: (data) => {
				return `${formatToMoney(data.text / 100)}元`
			},
		}, {
			label: '代扣费 (7%)',
			dataIndex: 'holdFee',
			customRender: (data) => {
				return `${formatToMoney(data.text / 100)}元`
			},
			label: '实际到账',
			dataIndex: 'realAmt',
			customRender: (data) => {
				return `${formatToMoney(data.text / 100)}元`
			},
		}],
		[{
			label: '发票号',
			dataIndex: 'invoiceCode',
		}, {
			label: '发票凭证',
			dataIndex: 'invoiceUrl',
		}, {
			label: '备注',
			dataIndex: 'remark',
		}, {
			label: '审核状态',
			dataIndex: 'auditStatus',
			customRender: (data) => {
				return selectDictLabel(ZZB_AGENT_NO_STATUS, data.text)
			},
		}, {
			label: '审核失败原因',
			dataIndex: 'rejectReason',
		}]
	])

	const queryData = ref({})
	const getForm = () => {
		profitApi.findIdDraw(queryData.value).then((res) => {
			if (res.code != 200) return
			formData.value = res.data
		})
	}
	const titleMap = {
		add: '新增',
		update: '修改',
		view: '查看',
	}

	const initFormView = () => {
		getForm()
		// 动态设置标题
		uni.setNavigationBarTitle({
			title: titleMap[formType.value]
		})
	}

	onLoad(async (options) => {
		formType.value = options.type ?? 'view'
		if (options.id) {
			queryData.value.id = options.id
			initFormView()
		}
	})
	onReady(() => {
		// paging.value.reload()
		nextTick(() => {})
	})
</script>
<style lang='scss' scoped>
	.view-group {
		background-color: #fff;
	}

	.operate-box {
		position: fixed;
		z-index: 99;
		bottom: 50rpx;
	}

	.tar {
		:deep(.u-input) {
			text-align: right !important;
		}
	}
</style>